<!--
 * @Description: 
 * @Author: 张文韬
 * @Date: 2024-06-24 15:29:13
 * @LastEditTime: 2024-07-16 14:08:52
 * @LastEditors: 张文韬
 * @Reference: 
-->
<template>
  <div m-10px>
    <EDescriptions
      :column="2" 
      :border="true"
      :form-options="detailOptions"
      :form-data="data">
    </EDescriptions>
    <ETable 
      class="mt-20px"
      :data="tableData" 
      :columns="columns" 
      :loading="loading">
      <template #handleSlot="{scope}">
        <el-button type="warning" @click="edit(scope.row)" size="small">下载</el-button>
        <el-button type="danger" @click="remove(scope.row)" size="small">删除</el-button>
      </template>
    </ETable>
  </div>
</template>

<script setup>

import EDescriptions from '@/components/e-descriptions';
import ETable from '@/components/e-table'
import { detailOptions, columns } from './config';
import { destination } from '@/api/insurance';

const props = defineProps({
  loading: {
    type: Boolean,
    default: false
  },
  data: {
    type: Object,
    default: () => {}
  },
})

const tableData = ref([])

const remove = ({id}) => {
  ElMessageBox.confirm(`确定要删除吗`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    center: true
  }).then(async () => {
    // await destination({ id, route: 'del' })
    // getData()
  })
}

const getData = async() => {
  console.log(111, props.data);
  
  tableData.value = props.data.insuredList?.map(o => ({
    ...o,
    holderName: props.data.applicantInfo.name
  }))
  // const res = await destination({route: 'view'})
  // tableData.value = [{name: '鱼大头 YU DATOU', document_number: '141182199209080033', gender: '男', birthday: '1990-01-01'}]//res.data
}

const getTableData = () => tableData.value

defineExpose({
  getTableData
})

onMounted(async() => {
  console.log('onMounted');
  getData()
})

</script>